package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dto.search.BoxSearchParams;
import cn.lili.modules.promotion.entity.vos.BoxLotteryTicketVO;
import cn.lili.modules.promotion.service.BoxLotteryTicketService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;

/**
 * 奖券管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/promotion/box/lottery/ticket")
public class BoxLotteryTicketController {

    private BoxLotteryTicketService boxLotteryTicketService;

    /**
     * 获取奖券，列表分页
     *
     * @param boxSearchParams 搜索条件
     * @return 结果
     */
    @GetMapping("/page")
    public ResultMessage<Object> pageBox(BoxSearchParams boxSearchParams) {
        return boxLotteryTicketService.pageBox(boxSearchParams);
    }
    
    /**
     * 作废奖券
     */
    @PostMapping("/cancellation")
    public ResultMessage<Object> cancellation(@RequestParam String id, String remark) {
        boxLotteryTicketService.cancellation(id, remark);
        return ResultUtil.success();
    }

    /**
     * 恢复奖券
     */
    @PostMapping("/recover")
    public ResultMessage<Object> recover(@RequestParam String id) {
        boxLotteryTicketService.recover(id);
        return ResultUtil.success();
    }

    /**
     * 新增奖券
     */
    @PostMapping("/add")
    public ResultMessage<Object> addBoxGoods(@RequestBody BoxLotteryTicketVO boxLotteryTicketVO) {
        return boxLotteryTicketService.addBoxGoods(boxLotteryTicketVO);
    }


    /**
     * 批量删除奖券
     */
    @DeleteMapping("/delete")
    public ResultMessage<Object> deleteBoxGoods(@RequestParam String ids) {
        return ResultUtil.data(boxLotteryTicketService.removeBatchByIds(Collections.singletonList(ids.split(","))));
    }

    /**
     * 修改奖券
     */
    @PutMapping("/update")
    public ResultMessage<Object> updateBoxGoods(@RequestBody BoxLotteryTicketVO boxLotteryTicketVO) {
        return boxLotteryTicketService.updateBoxGoods(boxLotteryTicketVO);
    }


}
